package com.kb.controller.flow;

import cn.hutool.core.date.DateUtil;
import com.kb.common.MeException;
import com.kb.dto.OneStopCode;
import com.kb.dto.flow.*;
import com.kb.dto.HistoricalFactory;
import com.kb.service.flow.CustComplaintService;
import com.kb.service.flow.FlowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@RestController
@RequestMapping("flow")
public class FlowController {

    @Resource
    private FlowService flowService;
    @Resource
    private CustComplaintService custComplaintService;

    //获取历史工厂
    @PostMapping("/getHistoricalFactory")
    public List<HistoricalFactory> getHistoricalFactory(String keyword, String code_eq) throws MeException {
        if (Objects.isNull(keyword) || keyword.trim().isEmpty()) {
            keyword = code_eq;
        }
        return flowService.getHistoricalFactory(keyword);
    }

    /**
     * 获取一站式编码随机数
     *
     * @param keyword
     * @return
     * @throws MeException
     */
    @PostMapping("/getOneStopCodeRandom")
    public List<Map<String, Object>> getOneStopCodeRandom(String keyword) throws MeException {
        Map<String, Object> map = new HashMap<>();
        map.put("code", flowService.getOneStopCodeRandom(keyword));
        map.put("date", DateUtil.now());
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(map);
        return list;
    }

    /**
     * 获取一站式编码
     *
     * @param keyword
     * @return
     * @throws MeException
     */
    @PostMapping("/getOneStopCode")
    public Map<String, Object> getOneStopCode(@RequestBody OneStopCode keyword) throws MeException {
        Map<String, Object> map = new HashMap<>();
        map.put("code", flowService.getOneStopCode(keyword));
        map.put("date", DateUtil.now());
        return map;
    }

    @PostMapping("/getDisposalOrderNumber")
    public List<DisposalOrderNumber> getDisposalOrderNumber(String keyword) throws MeException {
        return custComplaintService.getDisposalOrderNumber(keyword);
    }

    /**
     * 获取   本月初账面应收余额
     *
     * @param keyword
     * @return
     * @throws MeException
     */
    @PostMapping("/getBalanceReceivable")
    public List<BalanceReceivable> getBalanceReceivable(String keyword, String keywordType) throws MeException {
        return flowService.getBalanceReceivable(keyword);
    }

    //获取IT配件耗材
    @PostMapping("/getITPartsConsumables")
    public List<PartsConsumables> getITPartsConsumables(String keyword) throws MeException {
        return flowService.getITPartsConsumables(keyword);
    }

    //获取crm所有客户信息
    @PostMapping("/getCrmCustomerInfo")
    public List<CrmCustomerInfo> getCrmCustomerInfo(String keyword, String userName_eq) throws MeException {
        return flowService.getCrmCustomerInfo(keyword, userName_eq);
    }
}
